package com.zhou.basics.common.core;

import com.zhou.basics.common.enums.ResultCode;
import lombok.Data;
import lombok.NoArgsConstructor;
import com.alibaba.fastjson.JSON;

/**
 * @ProjectName: tsqingcheng
 * @ClassName: Result
 * @Time: 2020/2/26
 * @Author: zhou24
 * @Description:
 * @Experience:
 */
@Data
@NoArgsConstructor
public class Result {
    private Integer code;
    private String message;
    private Object data;

    public Result (Integer code,String message){
        this.code=code;
        this.message=message;
    }
    public Result setCode(ResultCode resultCode){
        this.code=resultCode.code;
        this.message=resultCode.msg;
        return this;
    }

    public Result success(Object data){
        this.code=200;
        this.message="success";
        this.data=data;
        return this;
    }

    public Result success(){
        this.code=200;
        this.message="success";
        return this;
    }

    @Override
    public String toString() {
        return JSON.toJSONString(this);
    }
}
